// user

let state = {
    userInfo: null,
    cachedPages: [],
}

let getters = {
    getUserInfo(state) {
        return state.userInfo
    },
    getCachedPages(state) {
        return state.cachedPages
    },
}

let mutations = {
    SET_USERINFO(state, payload) {
        state.userInfo = payload
    },
    SET_CACHED_PAGES(state, payload) {
        state.cachedPages = payload
    },
}

let actions = {
    addCachedPages({ state }, payload) {
        if (!state.cachedPages.includes(payload)) {
            state.cachedPages.push(payload)
        }
    },
    delCachedPages({ state }, payload) {
        let arr = []
        state.cachedPages.forEach(item => {
            if (!payload.includes(item)) arr.push(item)
        })
        state.cachedPages = arr
    },
}

export default {
    namespaced: true,
    state: state,
    getters: getters,
    mutations: mutations,
    actions: actions,
}
